<?php

class BrandsController extends AppController {

    var $name = 'Brands';
    var $helpers = array('Html', 'Session', 'Javascript', 'Link');
    var $uses = array('User');

    function beforeFilter() {
        $this->Auth->allow(array('*'));
        parent::beforeFilter();
    }

    function index() {
        echo __METHOD__;
        $this->redirect(array('action' => 'brand'));
    }

    function brand($cat_slug ="") {
        echo __METHOD__;
        $params = $this->params;
        //pr($params['named']['letter']);
        //exit;
        if (isset($cat_slug) and ($cat_slug)) {
            $this->set('cat_slug', $cat_slug);
            $cat_id = $this->__get_slug_to__id($cat_slug, "Category");

            $conditions = 'Brand.cat_id Like "%' . $cat_id . '%"';
            if (isset($params['named']['letter']) and ($params['named']['letter'])) {
                $conditions = $conditions . ' and Brand.name Like "' . strtolower($params['named']['letter']) . '%"';
            }
        } else {
            if (isset($params['named']['letter']) and ($params['named']['letter'])) {
                $conditions = 'Brand.name Like "%' . strtolower($params['named']['letter']) . '%"';
            } else {
                $conditions = "";
            }
        }
        $this->paginate['Brand'] = array('conditions' => '' . $conditions . '',
            'limit' => 10,
            'fields' => array('Brand.*'),
            'order' => 'Brand.name ASC'
        );
        $Brands = $this->paginate('Brand');
        //pr($Brands);
        //exit;
        $this->Set('Brands', $Brands);
    }

}
